#include "securityclient.h"
#include "Security\SecurityDLL.h"
#include <QMessageBox>

SecurityClient::SecurityClient(QWidget *parent)
	: QDialog(parent)
{
	ui.setupUi(this);

	connect(ui.btnGen,SIGNAL(clicked()),this, SLOT(onRegKey()));
	connect(ui.btnExit,SIGNAL(clicked()),this, SLOT(close()));

	char machine_code[1024];
	GenMachineCode(machine_code,0);
	ui.lineMac->setText(machine_code);	
}

SecurityClient::~SecurityClient()
{

}

void SecurityClient::onRegKey()
{
	QString qkey = ui.textKey->toPlainText();
	if(qkey.length() != 35)
	{
		QMessageBox::information(this,"","Key error,please check");
		return;
	}

	std::string reg_key = qkey.toStdString();
	int ret = Register(reg_key.c_str());
	if(ret == SECURITY_OK)
	{
		QMessageBox::information(this,"","Reg successed");
	}
	else
		QMessageBox::information(this,"","Reg error:" + QString::number(ret));
}